package com.wck.car.controller;

import com.wck.car.CarBrandDescService;
import com.wck.car.CarSeriesDescService;
import com.wck.car.model.CarBrandDesc;
import com.wck.car.model.CarSeriesDesc;
import com.wck.car.oyz.CarSeriesDescType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
public class CarSeriesDescController {

    @Resource
    private CarBrandDescService carBrandDescService;
    @Resource
    private CarSeriesDescService carSeriesDescService;

    @PostMapping("/getCarSeriesDesc")
    public void getCarSeriesDesc(){
        List<CarBrandDesc> list = carBrandDescService.lambdaQuery().select(CarBrandDesc::getCarLink,CarBrandDesc::getId).list();
        ArrayList<CarSeriesDesc> seriesDescList = new ArrayList<>();
        list.parallelStream().forEach(s->{
            List<CarSeriesDesc> carSeriesHtml = CarSeriesDescType.getCarSeriesHtml(s);
            carBrandDescService.updateById(s);  //修改车辆品牌相关信息
            seriesDescList.addAll(carSeriesHtml);
        });
        carSeriesDescService.saveBatch(seriesDescList);
    }

}
